package com.ltkj.baseplatform.controller;

import com.ltkj.baseplatform.domain.WuserPartner;
import com.ltkj.baseplatform.domain.req.WuserPartnerAddReq;
import com.ltkj.baseplatform.service.IWuserPartnerService;
import com.ltkj.common.core.web.controller.BaseController;
import com.ltkj.common.core.web.domain.AjaxResult;
import com.ltkj.common.core.web.page.TableDataInfo;
import com.ltkj.common.log.annotation.Log;
import com.ltkj.common.log.enums.BusinessType;
import com.ltkj.common.security.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 游客信息Controller
 * 
 * @author xupf
 * @date 2023-10-10
 */
@Api(tags = "游客信息")
@RestController
@RequestMapping("/partner")
public class WuserPartnerController extends BaseController
{
    @Autowired
    private IWuserPartnerService wuserPartnerService;

    /**
     * 查询游客信息列表
     */
    @ApiOperation("查询游客信息列表")
    @GetMapping("/list")
    public TableDataInfo list(WuserPartner wuserPartner)
    {
//        startPage();
        if (null == wuserPartner.getUesrId()) {
            wuserPartner.setUesrId(SecurityUtils.getLoginUser().getUserid());
        }
        List<WuserPartner> list = wuserPartnerService.selectWuserPartnerList(wuserPartner);
        return getDataTable(list);
    }

    /**
     * 获取游客信息详细信息
     */
    @ApiOperation("获取游客信息详细信息")
    @GetMapping(value = "/{partnerId}")
    public AjaxResult getInfo(@PathVariable("partnerId") Long partnerId)
    {
        return success(wuserPartnerService.selectWuserPartnerByPartnerId(partnerId));
    }

    /**
     * 获取当前登录人信息
     */
    @ApiOperation("获取当前登录人信息")
    @GetMapping(value = "/getSelfInfo")
    public AjaxResult getSelfInfo()
    {
        WuserPartner wuserPartner = new WuserPartner();
        wuserPartner.setUesrId(SecurityUtils.getLoginUser().getUserid());
        wuserPartner.setIsSelf("1");
        return success(wuserPartnerService.selectWuserPartnerList(wuserPartner).get(0));
    }

    /**
     * 新增游客信息
     */
    @ApiOperation("新增游客信息")
    @Log(title = "游客信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WuserPartnerAddReq wuserPartnerAddReq)
    {
        return wuserPartnerService.insertWuserPartner(wuserPartnerAddReq);
    }

    /**
     * 修改游客信息
     */
    @ApiOperation("修改游客信息")
    @Log(title = "游客信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WuserPartnerAddReq wuserPartnerAddReq)
    {
        return wuserPartnerService.updateWuserPartner(wuserPartnerAddReq);
    }

    /**
     * 删除游客信息
     */
    @ApiOperation("删除游客信息")
    @Log(title = "游客信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{partnerIds}")
    public AjaxResult remove(@PathVariable Long[] partnerIds)
    {
        return toAjax(wuserPartnerService.deleteWuserPartnerByPartnerIds(partnerIds));
    }


    /**
     * 获取EidToken
     * @param appKey 应用KEY，用于区分不同小程序。
     *                  -生态岛（可以不传）：island
     *                  -体育场：motion
     * @return token
     */
    @GetMapping("/getEidToken")
    @ApiOperation("根据游客信息获取EidToken")
    @Log(title = "根据游客信息获取EidToken", businessType = BusinessType.OTHER)
    public AjaxResult getEidToken(@ApiParam(value = "应用KEY，用于区分不同小程序。生态岛（可以不传）：island 体育场：motion") String appKey,
                                  @ApiParam(required = true, value = "身份证号码") String idCode,
                                  @ApiParam(required = true, value = "身份证姓名") String name) {
        return wuserPartnerService.getEidToken(appKey, idCode, name);
    }


    /**
     * 获取游客信息E证通结果信息
     * @param eidToken eidToken
     * @param id 游客信息id
     * @return AjaxResult
     */
    @GetMapping("/getEidResult")
    @ApiOperation("获取游客信息E证通结果信息")
    @Log(title = "获取游客信息E证通结果信息", businessType = BusinessType.OTHER)
    public AjaxResult getEidResult(@ApiParam(required = true) String eidToken, @ApiParam(value = "游客信息id") Long id) {
        return wuserPartnerService.getEidResult(eidToken, id);
    }
}
